﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace SetDisplayFrequencyArgs
{
    public static class Shared
    {
        public static void SetFrequence(int hz)
        {
            Win32.Display.DEVMODE dm = new Win32.Display.DEVMODE();
            dm.dmSize = (short)Marshal.SizeOf(dm);
            Win32.Display.EnumDisplaySettings(null, Win32.Display.ENUM_CURRENT_SETTINGS, ref dm);

            dm.dmDisplayFrequency = hz;
            dm.dmFields = Win32.Display.DM.DisplayFrequency;

            Win32.Display.DISP_CHANGE ret = Win32.Display.ChangeDisplaySettings(ref dm, Win32.Display.CDS_UPDATEREGISTRY);

            Console.WriteLine("Change Display Frequency to " + hz.ToString() + " Hz");
            Console.WriteLine(ret.ToString());

            //Thread.Sleep(1000);

            if (ret != Win32.Display.DISP_CHANGE.Successful)
            {
                Console.WriteLine();
                Console.WriteLine("Press Enter to exit.");
                Console.ReadLine();
            }

        }

    }
}
